package com.bnlr.lrparking.appui.approve;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.app.AppConfig;
import com.bnlr.lrparking.model.ApproveMessageM;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * Created by hp on 2017/8/31.
 * 实名认证成功
 */
public class ApproveSuccessActivity extends BaseActivity {

    private TextView tvNavTitle,approve_name,tv_approve_card,tv_approve_card1,tv_card_type;
    private ImageView img_approvetype,image_sex,image_portrait;
    private ApproveMessageM.DataBean dataResult;
    private LinearLayout llSuccess, llFail;
    private TextView again_rz, text_reason;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_approvesuccess);
        Intent intent = getIntent();
        dataResult = (ApproveMessageM.DataBean) intent.getSerializableExtra("isRealNameAuth");

        initView();
    }

    private void initView() {
        tvNavTitle = (TextView) findViewById(R.id.tv_nav_title);
        tvNavTitle.setText("实名认证");
        img_approvetype = (ImageView) findViewById(R.id.img_approvetype);
        image_sex=(ImageView)findViewById(R.id.image_sex);
        approve_name=(TextView)findViewById(R.id.approve_name);
        tv_approve_card=(TextView)findViewById(R.id.tv_approve_card);
        tv_approve_card1=(TextView)findViewById(R.id.tv_approve_card1);
        tv_card_type=(TextView)findViewById(R.id.tv_card_type);
        image_portrait=(ImageView)findViewById(R.id.image_portrait);
        llSuccess = (LinearLayout) findViewById(R.id.ll_success);
        llFail = (LinearLayout) findViewById(R.id.ll_fail);
        again_rz = (TextView)findViewById(R.id.again_rz);
        text_reason = (TextView)findViewById(R.id.text_reason);
        if (dataResult == null) {
            ToastUtils.showShort("系统出错，请稍后再试");
            return;
        }
        if (dataResult.getIsRealNameAuth().equals("1")) {
            Glide.with(this)
                    .load(AppConfig.getInstance().getString("photo", ""))
                    .bitmapTransform(new CropCircleTransformation(this))
                    .placeholder(R.mipmap.personal_head)
                    .error(R.mipmap.personal_head)
                    .into(image_portrait);
            //  已认证
            approve_name.setText(dataResult.getName());
            String cardId = dataResult.getIdCard();
            String card = cardId.substring(0,1) + "****************" + cardId.substring(cardId.length()-1);
            tv_approve_card.setText(card);
            tv_approve_card1.setText(card);
            //证件类型
            if (dataResult.getCardType().equals("0")){
                tv_card_type.setText("身份证");
            }else if (dataResult.getCardType().equals("1")){
                tv_card_type.setText("驾驶证");
            }else if (dataResult.getCardType().equals("2")){
                tv_card_type.setText("护照");
            }else if (dataResult.getCardType().equals("3")){
                tv_card_type.setText("港澳通行证");
            } else {
                tv_card_type.setText("审核中");
            }
            img_approvetype.setImageResource(R.mipmap.authentication_success);

            //性别
            if (dataResult.getSex() == 0){
                image_sex.setImageResource(R.mipmap.icon_boy);
            }else {
                image_sex.setImageResource(R.mipmap.icon_girl);
            }
        } else {
            llFail.setVisibility(View.VISIBLE);
            llSuccess.setVisibility(View.GONE);
            text_reason.setText("原因："+dataResult.getRejectReason());
            again_rz.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(ApproveSuccessActivity.this, ApproveActivity.class);
                    startActivity(intent);//跳转并发送请求码
                    finish();
                }
            });
        }

    }


}
